package com.go.where.manager.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.go.where.manager.common.Constants;
import com.go.where.manager.dao.TeacherDao;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.pojo.TeacherInfo;
import com.go.where.manager.pojo.user.UserInfoVO;
import com.go.where.manager.service.TeacherService;

@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {

	@Resource(name = "teacherDao")
	private TeacherDao teacherDao;

	@Override
	public TeacherInfo queryByPrimartKey(String cid) {
		return teacherDao.getByKey(cid);
	}

	@Override
	public Pagination<TeacherInfo> queryPage(TeacherInfo teacherInfo) {
		Integer count = teacherDao.totalCount(teacherInfo);
		teacherInfo.calculate();
		List<TeacherInfo> list = teacherDao.queryList(teacherInfo);
		Pagination<TeacherInfo> page = teacherDao.queryPagination(count, list,
				teacherInfo);
		return page;
	}

	@Override
	public int save(TeacherInfo teacherInfo, UserInfoVO currentUser) {
		teacherInfo.setPublishTime(new Date());
		teacherInfo.setUserId(currentUser.getUserId());
		teacherInfo.setIsDelete(Constants.NOT_DELETED);
		return teacherDao.insert(teacherInfo);
	}

	@Override
	public int update(TeacherInfo teacherInfo, UserInfoVO currentUser) {
		teacherInfo.setUpdateTime(new Date());
		teacherInfo.setUserId(currentUser.getUserId());
		return teacherDao.update(teacherInfo);
	}

	@Override
	public List<TeacherInfo> queryAll() {
		return teacherDao.queryAll();
	}

}
